//
//  YYJLFunnyAnswerController.m
//  YuanyangJinlou
//
//  Created by mac004 on 2017/1/6.
//  Copyright © 2017年 suli19910309@qq.com. All rights reserved.
//

#import "YYJLFunnyAnswerController.h"
#import "YYJLFunnyAnswerCell.h"
#import "YYJLTestController.h"
@interface YYJLFunnyAnswerController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>
{
    UICollectionView * _collectionview;
}

@end

@implementation YYJLFunnyAnswerController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setTitleView:@"趣味答题"];
    [self setBackItem];
    [self creatUI];
    
}
-(void)creatUI{
    UICollectionViewFlowLayout* layout=[[UICollectionViewFlowLayout alloc]init];
    _collectionview=[[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) collectionViewLayout:layout];
    _collectionview.dataSource=self;
    _collectionview.delegate=self;
    _collectionview.backgroundColor=UIColorFromHex(0xf7f7f7);
    [self.view addSubview:_collectionview];
    [_collectionview registerClass:[YYJLFunnyAnswerCell class] forCellWithReuseIdentifier:@"cell"];
    [_collectionview registerClass:[CollectHeaderView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header"];
    
}
#pragma mark--collectionview
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 6;
}
-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    YYJLFunnyAnswerCell*cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    return cell;
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return CGSizeMake(113*PER_WIDTH, 150*PER_HEIGHT);
}
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    return UIEdgeInsetsMake(10*PER_HEIGHT,12*PER_WIDTH, 20*PER_HEIGHT, 6*PER_WIDTH);
}
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    return 6*PER_WIDTH;
}
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    return 20*PER_HEIGHT;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    YYJLTestController * test =[[YYJLTestController alloc]init];
    test.testType =FunyTest;
    [self.navigationController pushViewController:test animated:YES];
}

-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    if (kind==UICollectionElementKindSectionHeader) {
        CollectHeaderView * headerView=[collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"header" forIndexPath:indexPath];
        
     
       
        UILabel*lab=[MyControl createLabelWithFrame:CGRectMake(12*PER_WIDTH, 15*PER_HEIGHT, SCREEN_WIDTH, 15*PER_HEIGHT) Font:15 Text:@"共6关,每关有10道题" Color:BLACK_COLOR];
        [headerView addSubview:lab];
        
        return headerView;
    }
    return nil;
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
    return CGSizeMake(SCREEN_WIDTH, 40*PER_HEIGHT);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
